<?php

/** 
 * 学生充值记录统计模型(mongo)
 * @property User_order_mdl $order
 */
class Tongji_user_recharge_mdl extends Mongo_Model {
	public function __construct() {
		$this->collName = 'tongji_user_recharge';
		parent::__construct ();
	}
	
	public function getUserTongji($fields=array(),$where=array(),$sort=array(),$sortKey){
		
		$lists = $this->coll->find($where,$fields)
							->sort($sort);
		$lists =  $this->toArray($lists);
		
		$rst = array();
		
		if( !empty($lists) ){
			foreach ($lists as $k=>$v){
				$rst[$v['uid']]['ctime'] = $where['ctime']['$gte'];
				if ( isset($where['ctime']['$lte']) ){
					$rst[$v['uid']]['ctime'] .= ' - '.$where['ctime']['$lte'];
				}
				$rst[$v['uid']]['name'] = $v['name'];
				$rst[$v['uid']]['uid'] = $v['uid'];
				$rst[$v['uid']]['sid'] = $v['sid'];
				$rst[$v['uid']]['sname'] = $v['sname'];
				$rst[$v['uid']]['amount_count'] = (int)(isset($rst[$v["uid"]]['amount_count'])?($rst[$v["uid"]]['amount_count']+$v['amount_count']):$v['amount_count']);
			}
			
			//排序
			$rst = $this->array_paixu($rst,$sortKey);	
			
		}
		
		return $rst;
	}

	public function array_paixu($list_scene,$key='amount_count',$desc='desc'){
		if($desc=='desc'){
			array_multisort(array_column($list_scene,$key),SORT_DESC,$list_scene);
		}else{
			array_multisort(array_column($list_scene,$key),SORT_ASC,$list_scene);
		}
		return $list_scene;
	}
	
}

